You are here: Home / Topics / Search / java
Showing 380 Search Results for : java

Program to explain Generic Interfaces in Java

Filed under: Java on 2024-04-13 09:09:43
//  Program to explain Generic Interfaces.interface MinMax<T extends Comparable<T>> {T min();T max();}class MyClass<T extends Comparable<T>> implements MinMax<T> {T[ ] vals;MyClass(T[ ] o) { vals = o;}public T min() { T v = vals[0

Program to explain Generic class with Wildcard in Java

Filed under: Java on 2024-04-13 09:06:42
// Program to explain Generic class with Wildcard.class  GenericStats<T extends Number> {T[ ]  nums;   GenericStats(T[ ]  o) { nums = o;}double average() { double sum = 0.0; for(int i=0; i < nums.length; i++) {  sum += nums[ i

Program 2 to explain Generic method with Bounded type in Java

Filed under: Java on 2024-04-12 18:38:35
// Program to explain Generic method with Bounded type.// GenericType<? extends upperBoundType>import java.util.ArrayList;import java.util.List;public class  GenericTest10 {public static double getAverage(List<? extends Number> numberList) { double total = 0.0; f

Program to explain Generic Method in Java

Filed under: Java on 2024-04-12 18:37:56
// Program to explain Generic Method.public class  GenericTest7 {// generic method printArraypublic static <T> void printArray(T[ ] inputArray) { // display array elements for (T element : inputArray)  System.out.printf("%s  ", element); System.out.print

Program to explain Simple Generic class in Java

Filed under: Java on 2024-04-12 18:32:56
// Program to explain Simple Generic class.class   A<T> {T ob;A(T o) { ob = o;}T getob() { return ob;}void showType() { System.out.println("Type of T is " + ob.getClass().getName());}}public class  GenericTest1{public static void main(String args[ ]

How did I Setup bootstrap css in my Java EE project?

Filed under: Java EE on 2024-03-30 20:48:24
During my setup of java EE project. I faced one problem. I was unable to include bootstrap css in my project. I tried many ways to do this.<link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css"/>But it was not being included in my webpages (.jsp pages) so i searched on goo

How to get Database data using Hibernate? Explained by Impl class

Filed under: Java on 2024-03-11 21:27:10
Before viewing this example. Go and learn  (Hibernate Configuration using java file)package com.mysite.firstJavaDbApp.serviceImpl;import java.util.List;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import com.mysite.firstJavaDbApp.beans.Employ

Hibernate Configuration using Java Singleton Class

Filed under: Java on 2024-03-11 21:24:26
package com.mysite.firstJavaDbApp.config;import java.util.Properties;import org.hibernate.SessionFactory;import org.hibernate.boot.registry.StandardServiceRegistryBuilder;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import com.mysite.firstJavaDbApp.beans.Employ

Java Program to find area of triangle

Filed under: Java on 2024-03-05 21:41:47
import java.util.Scanner;class AreaOfTriangle {  public static void main(String args[])    {              Scanner s= new Scanner(System.in);               System.out.println("Enter the width

Java Program to find area of rectangle

Filed under: Java on 2024-03-05 21:40:08
import java.util.Scanner;class AreaOfRectangle {  public static void main(String args[])    {              Scanner s= new Scanner(System.in);              System.out.println("Enter the lengt

Java Program to find area of circle

Filed under: Java on 2024-03-05 21:33:32
import java.util.Scanner;class AreaOfCircle {  public static void main(String args[])    {              Scanner s= new Scanner(System.in);               System.out.println("Enter the radius:

Classes in Java

Filed under: Java Tutorial on 2024-03-03 20:42:59
In Object-Oriented Programming language, Classes and Objects are the essential building blocks. The “class” keyword is used to declare the class followed by a reference name.Syntax:class Car {//class body}Classes are known as the blueprint of object creation. Classes that are defined by the user

Type Casting in Java

Filed under: Java Tutorial on 2024-03-03 20:36:44
In Java, Type Casting is a process of converting a variable of one data type into another.Type casting can be categorized into two types:Implicit type castingExplicit type castingImplicit typecasting:It is known as widen or automatic type casting. The process to convert a small range data type varia

Primitive Data Types in java

Filed under: Java Tutorial on 2024-03-01 21:08:59
There are eight primitive data types that are supported in Java programming language. These are the fundamental and predefined datatypes of the programming language. Java determines the size of each primitive data type, it cannot be changed. Reserved keywords represent primitive data types.The primi

Understanding Variables in Java

Filed under: Java Tutorial on 2024-03-01 20:50:25
In Java, the variables can be declared to store data in the program for a specific time. In a programming language, few variations are there todeclare a variable. The following program will explain to declare and then initialize an int variable.public static void main(String[] args) {int data1;data1

Variable and Data Type in Java

Filed under: Java Tutorial on 2024-03-01 20:43:00
VariableVariables occupy the memory to store data for a particular time. Data Type A data type is used to identify the size and type of information stored in a variable. Data types help in memory management. It helps to assign thememory depending upon the type of data type. Most importantl

First Program in Java

Filed under: Java Tutorial on 2024-03-01 20:39:53
This Java program has been developed to display the text 'Hello Planet!' onthe console screen.// File-Name: Hello.javapublic class Hello {     public static void main(String[] args) {     // Displaying "Hello Planet!" on the console     System.out.println

what is JDK, JRE, Garbage Collector and Classpath in Java

Filed under: Java Tutorial on 2024-03-01 16:56:07
Java Development Kit (JDK): Overview: The JDK is a comprehensive package for Java development. It encompasses essential components like the compiler, Java Runtime Environment (JRE), Java debuggers, documentation, and more. To write, compile, and run Java programs, it's imperative to install the

Program to Serialize Student Deserialize student object in Java

Filed under: Java on 2024-03-01 06:48:15
// Program to Serialize Student Deserialize student object.import java.io.*;class Student implements Serializable{int rno;String sname;double marks; // ConstructorStudent( int r, String nm, double m ){ rno = r; sname = nm; marks = m;}void display(){ System.out.println(" Roll

Program to Serialize Student object in Java

Filed under: Java on 2024-03-01 06:47:34
// Program to Serialize Student object student object.import java.io.*;class Student implements Serializable{int rno;String sname;double marks; // ConstructorStudent( int r, String nm, double m ){ rno = r; sname = nm; marks = m;}void display(){ System.out.println(" Roll No. 

Program to De-serialize object of Box class in Java

Filed under: Java on 2024-03-01 06:46:15
// Program to De-serialize object of Box class.import java.io.*;import java.util.*;// Box classclass Box  implements  Serializable{// instance variablesprivate double width;private double height;private double depth;// default constructorBox(){ width = 0; height = 0; depth =

Program to Serialize object of Box class in Java

Filed under: Java on 2024-03-01 06:45:40
// Program to Serialize object of Box class.import java.io.*;import java.util.*;// Box classclass  Box  implements Serializable{// instance variablesprivate double width;private double height;private double depth;// default constructorBox(){ width = 0; height = 0; depth = 0;

Program to read data from text file using FileReader in Java

Filed under: Java on 2024-03-01 06:44:32
// Program to read data from text file using // FileReader  and display it on the monitor.import java.io.*;class FileReaderDemo{public static void main( String args[ ] ) throws IOException{ // attach file to FileReader FileReader fr = null; try {  fr = new FileRead

What is Bytecode in the Development Process

Filed under: Java on 2024-02-27 15:43:54
Description: During the development process, Java source code is compiled into a special format called bytecode by the Javac compiler found in the Java Development Kit (JDK). This bytecode can be executed by the JVM and is saved with a .class extension.

What is Java Virtual Machine (JVM)?

Filed under: Java on 2024-02-27 15:42:54
Definition: The JVM is a critical component in the world of Java programming. It serves two primary functions: enabling Java applications to run across various devices and operating systems (the "Write once, run anywhere" principle) and efficiently managing and optimizing program memory. Technical D

Create a method named calc, which accepts an integer (int), a character (char) and one more integer (int), and depending on the character, returns the result

Filed under: Java on 2024-02-27 13:59:41
Create a method named calc, which accepts an integer (int), a character (char) and one more integer (int), and depending on the character, returns the result of the corresponding operation on numbers:'+' — sum of integers'-' — integer difference (first minus second)'*' — product of integers'/'

Ball Game example In Java

Filed under: Java on 2024-02-16 10:05:17
In this example, i have shown you an example which have mainly three classes:BallGame.javaBallGameImpl.javaApp.javaWhat does this game does?In this game, you will fill the no. of players and no. of balls. Then this game will distribute these balls among the players. After distribution it will tell h

Java program to sort an array in ascending order

Filed under: Java on 2023-10-29 09:53:28
In this java program, we are reading total number of elements (N) first, and then according the user input (value of N)/total number of elements, we are reading the elements. Then sorting elements of array in ascending order and then printing the elements which are sorted in ascending order.Programi

Java String compareTo() Example Code

Filed under: Java on 2023-10-26 21:45:31
class Main { public static void main(String[] args) {   String str1 = "Learn Java";   String str2 = "Learn Java";   String str3 = "Learn Kolin";   int result;   // comparing str1 with str2   result = str1.compareTo(str2);   S

Java String split() Example

Filed under: Java on 2023-10-26 21:42:57
class Main { public static void main(String[] args) {   String text = "Java is a fun programming language";   // split string from space   String[] result = text.split(" ");   System.out.print("result = ");   for (String str : result) {  &n

Program to use File class and its methods in Java

Filed under: Java on 2023-10-25 06:51:37
//  Program to use File class and its methodsimport java.io.*;class FileDemo{   public static void main(String args[ ])    {       File f = new File("FileDemo.java");       System.out.println("File : " + f.getName() + (f.isFile() 

Program to use URLConnection class in Java

Filed under: Java on 2023-10-25 06:49:31
//  Program to use URLConnection class.import java.io.*;import java.net.*;import java.util.Date;class URLConnectionDemo{public static void main(String args[ ]) throws Exception{ int ch; URL ob = new URL("http://www.bethedeveloper.com/java/"); URLConnection uc = u.openConnection()

Program to display all parts of URL in Java

Filed under: Java on 2023-10-25 06:48:59
// Program to display all parts of URL.import java.net.*;class URLDemo{public static void main( String args[ ] ) throws Exception{ URL ob = new URL("http://www.bethedeveloper.com/java/"); System.out.println(" Protocol : " + ob.getProtocol()); System.out.println(" Host : " + ob.getHost

Program to Display host name by IP address in Java

Filed under: Java on 2023-10-25 06:48:30
// Program to Display host name by IP address.import java.net.*;class HostName{public static void main( String args[ ] ) { // byte ad[ ] = { (byte)192, (byte)168, 1, 2 };  try {  // InetAddress ip = InetAddress.getByAddress( ad );  InetAddress ip = InetAddress.getB

Program to create Menu in AWT in Java

Filed under: Java on 2023-10-25 06:47:10
//  Program to create Menu in AWT.import java.awt.*;import java.applet.*;import java.awt.event.*;class MyMenu extends Frame implements ActionListener{String str="";CheckboxMenuItem cmiBold , cmiItalic;MenuItem miNew , miOpen , miSave, miCut, miCopy, miPaste, miRed, miGreen, miBlue;MyMenu(){&nbs

Program to explain Dialog class in Java

Filed under: Java on 2023-10-25 06:46:42
//  Program to explain Dialog class.import java.applet.*;import java.awt.*;import java.awt.event.*;class MyDialog extends Dialog implements ActionListener{  Button b1;  Label l1;    MyDialog( Frame f, String s, boolean u )  { super( f, s, u ); setLayout( 

Program to use GridBagLayout in Java

Filed under: Java on 2023-10-25 06:46:11
// Program to use GridBagLayout.import java.awt.*;import java.awt.event.*;public class GridBagLayoutDemo1 extends Frame{GridBagLayout gb;GridBagConstraints gbc;Button b1, b2, b3, b4, b5, b6, b7;public GridBagLayoutDemo1( String s ){ super( s );    gb = new GridBagLayout(); g

Program to explain CardLayout in Java

Filed under: Java on 2023-10-25 06:45:42
//  Program to explain CardLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="CardLayoutDemo" width=300 height=100></applet>*/public class CardLayoutDemo extends Applet implements ActionListener, MouseListener {Button b1, b2, b3, b4, b5;Panel 

Program to use GridLayout in Java

Filed under: Java on 2023-10-25 06:45:00
//  Program to use GridLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="GridLayoutDemo" width="300" height="150"></applet>*/public class GridLayoutDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(new Gr

Program to use Insets in Java

Filed under: Java on 2023-10-25 06:44:35
// Program to use Insets.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="InsetsDemo" width="300" height="150"></applet>*/public class InsetsDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(new BorderLayout());&nbs

Program to use BorderLayout in Java

Filed under: Java on 2023-10-25 06:44:03
//  Program to use BorderLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="BorderLayoutDemo" width="300" height="150"></applet>*/public class BorderLayoutDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(

Program to use FlowLayout in Java

Filed under: Java on 2023-10-25 06:43:36
//  Program to use FlowLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="FlowLayoutDemo" width="300" height="150"></applet>*/public class FlowLayoutDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(new Fl

Program to use Scrollbar AWT control in Java

Filed under: Java on 2023-10-25 06:43:08
//  Program to use Scrollbar AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ScrollbarDemo" width="250" height="150"></applet>*/public class ScrollbarDemo extends Applet implements AdjustmentListener, MouseMotionListener {String msg = 

Program to use List AWT control in Java

Filed under: Java on 2023-10-25 06:42:37
//  Program to use List AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ListDemo" width=300 height=150></applet>*/public class ListDemo extends Applet implements ActionListener {List os, browser;String msg = "";public void init() 

Program to use Choice AWT control in Java

Filed under: Java on 2023-10-25 06:42:11
//  Program to use Choice AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ChoiceDemo" width="300" height="150"></applet>*/public class ChoiceDemo extends Applet implements ItemListener {Choice os, browser;String msg = "";public void in

Program to use CheckboxGroup ( RadioButton ) AWT control in Java

Filed under: Java on 2023-10-25 06:41:41
//  Program to use CheckboxGroup ( RadioButton ) AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="RadioButtonDemo" width="250" height="100"></applet>*/public class RadioButtonDemo extends Applet implements ItemListener {String msg = "";

Program to use Checkbox AWT control in Java

Filed under: Java on 2023-10-25 06:40:54
// Program to use Checkbox AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="CheckBoxDemo" width="250" height="150"></applet>*/public class CheckBoxDemo extends Applet implements ItemListener {String msg = "";Checkbox cbRed, cbGreen, cbBlue;p

Program to use TextArea AWT control in Java

Filed under: Java on 2023-10-25 06:40:28
//  Program to use TextArea AWT control.import java.awt.*;import java.applet.*;/*<applet code="TextAreaDemo" width="300" height="200"></applet>*/public class TextAreaDemo extends Applet {public void init() { String val =  "Java SE 6 is the latest version of the m

Program to use TextField AWT control in Java

Filed under: Java on 2023-10-25 06:39:56
// Program to use TextField AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="TextFieldDemo" width=350 height=150></applet>*/public class TextFieldDemo extends Applet implements ActionListener {TextField tfname, tfpass;public void init() 

AWT frame class example in Java

Filed under: Java on 2023-10-25 06:39:22
//  Program to use Frame class.import java.awt.*;import java.awt.event.*;public class FrameTest extends Frame implements ActionListener{TextField tf;Button b;String s = "";   public  FrameTest(){ tf = new TextField( 10 ); b = new Button( "Show" );  add( "North

AWT button example in Java

Filed under: Java on 2023-10-25 06:38:57
//  Program to use Button  AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ButtonDemo" width=250 height=150></applet>*/public class ButtonDemo extends Applet implements ActionListener {String msg = "";Button b1, b2, b3;public void

AWT Label example in Java

Filed under: Java on 2023-10-25 06:38:35
// Program to use Label  AWT control.import java.awt.*;import java.applet.*;/*<applet code="LabelDemo" width=300 height=100></applet>*/public class LabelDemo extends Applet {public void init() { Label l1 = new Label("Java"); Label l2 = new Label("Programming");&n

Program to use Window Event in Java

Filed under: Java on 2023-10-19 07:07:54
//  Program to use Window Event.import java.awt.*;import java.awt.event.*;public class WindowEventDemo extends Frame implements WindowListener{public WindowEventDemo(){ addWindowListener( this ); setSize( 250, 150 ); setVisible( true );}public void windowOpened( WindowEvent we ){

Program to expain Fucus Event in Java

Filed under: Java on 2023-10-19 07:07:22
//  Program to expain Fucus Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="FocusEventDemo" width="200" height="100"></applet>*/public class FocusEventDemo extends Applet implements FocusListener{Button b1, b2, b3;Label l1, l2;public void init(){

Program to use MouseAdapter class as Inner class in Java

Filed under: Java on 2023-10-19 07:05:55
//  Program to use MouseAdapter class as Inner class.import java.applet.*;import java.awt.event.*;/*<applet code="MouseAdapterInnerTest" width="300" height="100"></applet>*/public class MouseAdapterInnerTest extends Applet {public void init() { addMouseListener(new My

Program to use MouseAdapter class in Java

Filed under: Java on 2023-10-19 07:05:02
//  Program to use MouseAdapter class.import java.applet.*;import java.awt.event.*;/*<applet code="MouseAdapterTest" width="200" height="100"></applet>*/public class MouseAdapterTest extends Applet {public void init() { addMouseListener(new MyMouseAdapter(this));}}cla

Program to explain Key Event with Virtual Key in Java

Filed under: Java on 2023-10-19 07:04:19
//  Program to explain Key Event with Virtual Key.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="KeyEventTest1" width="300" height="100"></applet>*/public class KeyEventTest1 extends Applet implements KeyListener {String msg = "";int X = 10, Y = 

Program to explain Key Event in Java

Filed under: Java on 2023-10-19 07:03:47
//  Program to explain Key Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="KeyEventTest"  width="300" height="200"></applet>*/public class KeyEventTest extends Applet implements KeyListener {String msg = "";int X = 10, Y = 20;&nbs

Program to explain Mouse Event and Mouse Motion Event in Java

Filed under: Java on 2023-10-19 07:03:14
//  Program to explain Mouse Event and Mouse Motion Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="MouseEventTest"  width="300" height="200"></applet>*/public class MouseEventTest extends Applet implements  MouseListener, MouseMo

Program to explain Mouse Motion Event in Java

Filed under: Java on 2023-10-19 07:02:42
//  Program to explain Mouse Motion Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="MouseMotionEventTest" width="300" height="200"></applet>*/public class MouseMotionEventTest extends Applet implements MouseMotionListener {String msg =

Program to explain Mouse Event in Java

Filed under: Java on 2023-10-19 07:01:58
//  Program to explain Mouse Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="MouseEventTest1"  width="300" height="200"></applet>*/public class MouseEventTest1 extends Applet implements MouseListener {String msg = "";int mouseX = 

Program to change color using setColor() method in Java

Filed under: Java on 2023-10-16 07:07:57
//  Program to change color using setColor() method.import java.awt.*;import java.applet.*;/*<applet code="GraphicsColor" width="300" height="200"></applet>*/public class  GraphicsColor  extends  Applet {public void paint(Graphics g) { Color c1 = new Co

Program to change Font using setFont() method in Java

Filed under: Java on 2023-10-16 07:07:16
//  Program to change Font using setFont() method.import java.awt.*;import java.applet.*;/*<applet code="DrawStringFontTest1a" width="200" height="100" ></applet>*/public class  DrawStringFontTest1a  extends Applet  {Font f;public void init() { setBackground

Program to draw Arc in Applet using fillArc() method in Java

Filed under: Java on 2023-10-16 07:06:07
// Program to draw Arc in Applet using fillArc() method.import java.awt.*;import java.applet.*;/*<applet code="FillArcTest1a" width="200" height="100" ></applet>*/public class  FillArcTest1a  extends  Applet  {public void paint(Graphics g) { setBackground( C

Program to draw Arc in Applet using drawArc() method in Java

Filed under: Java on 2023-10-16 07:05:37
// Program to draw Arc in Applet using drawArc() method.import java.awt.*;import java.applet.*;/*<applet code="DrawArcTest1a" width="200" height="100" ></applet>*/public class DrawArcTest1a extends Applet  {public void paint(Graphics g) { setBackground( Color.yellow );&nbs

Program to draw oval in Applet using drawOval() method in Java

Filed under: Java on 2023-10-16 07:04:38
//  Program to draw oval in Applet using drawOval() method.import java.awt.*;import java.applet.*;/*<applet code="DrawOvalTest1a" width="200" height="100" ></applet>*/public class DrawOvalTest1a extends Applet  {public void paint(Graphics g) { setBackground( Color.yel

Program to draw line in Frame using drawLine() method in Java

Filed under: Java on 2023-10-16 07:02:07
//  Program to draw line in Frame using drawLine() method.import java.awt.*;public class DrawLineTest1b  extends  Frame  {public DrawLineTest1b(){ setSize(200, 200); setVisible(true);}public void paint(Graphics g) { g.drawLine(20, 40, 180, 180);}public static 

Program to use Thread without Synchronization in Java

Filed under: Java on 2023-10-16 06:50:51
//  Program to use Thread without Synchronization.class Shared{void justDoIt( String s ){ System.out.println( " Starting ::: " + s ); try {  Thread.sleep( 500 ); } catch( InterruptedException e )  { } System.out.println( " Ending ::: " + s );}}class 

Program to use suspend( ) and resume( ) method in Java

Filed under: Java on 2023-10-16 06:48:35
// Program to use suspend( ) and resume( ) method.class NewThread implements Runnable{String tn;Thread t;NewThread( String tname ){ tn = tname; t = new Thread( this, tn ); System.out.println( " New Thread ::: " + t ); t.start();}public void run(){ try {  for( int i

Program to use setPriority( ) method of Thread in Java

Filed under: Java on 2023-09-22 06:48:31
//  Program to use setPriority( ) method.class A extends Thread{public void run(){ for( int i=1 ; i<=10 ; i++ ) {       System.out.println( " THREAD A = " + i ); } System.out.println( " END OF THREAD A." );}}class B extends Thread{public void run(){&nb

Program to extend multiple classes from Thread class in Java

Filed under: Java on 2023-09-22 06:47:47
//  Program to extend multiple classes from Thread class.class A extends Thread{public void run(){ for( int i=1 ; i<=10 ; i++) {  System.out.println( " Java" ); }}}class B extends Thread{public void run(){ for( int i=1 ; i<=10 ; i++) {  System.out.printl

Java Program to explain Main thread and currentThread( ) method

Filed under: Java on 2023-09-22 06:46:01
// Program Main thread and currentThread( ) methodclass CurrentThread{public static void main( String args[ ] ){ Thread t = Thread.currentThread(); System.out.println( "Current Thread is = " + t ); t.setName( "My Thread" ); System.out.println( "After Changing Name is = " + t );}}

Program 2 to create Applet with param tag in Java

Filed under: Java on 2023-09-20 06:41:28
//  Program to create Applet with param tag.import java.awt.*;import java.applet.Applet;/*<applet  code="AppletTest3.class" width="300" height="60"><param name="msg" value="Let's learn Applet.">  </applet>*/public class AppletTest3 extends Applet {String msg = "

Program to create Applet with param tag in Java

Filed under: Java on 2023-09-20 06:40:46
// Program to create Applet with param tag.import java.awt.*;import java.applet.Applet;/*<applet code="AppletTest2b.class" width="300" height="100"><param name="message" value="BIIT Computer Education" /></applet>*/public class  AppletTest2b  extends  Applet {St

Program to use Applet with Button and it's event in Java

Filed under: Java on 2023-09-20 06:39:13
// Program to use Applet with Button and it's event.import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.applet.Applet;import java.awt.Button;/*<applet code="AppletTest2.class" width="300" height="100"></applet>*/public class AppletTest2 extends Applet 

Program to use getCodeBase() and getDocumentBase() in Java

Filed under: Java on 2023-09-20 06:38:44
// Program to use getCodeBase() and getDocumentBase().import java.awt.*;import java.applet.*;import java.net.*;/*<applet code="Applet07" width="300" height="50"></applet>*/public class  Applet07  extends Applet{public void paint(Graphics g) { String msg;  UR

Program with param tag in applet tag in Java

Filed under: Java on 2023-09-20 06:38:12
//  Program with param tag in applet tag.import java.awt.*;import java.applet.*;/*<applet code="Applet06" width="300" height="50"><param name="message" value="Java makes the Web move!"></applet>*/public class  Applet06 extends Applet implements Runnable {String 

Program to display string in Status window in Java

Filed under: Java on 2023-09-20 06:36:38
//  Program to display string in Status window.import java.awt.*;import java.applet.*;/*<applet code="Applet04" width="300" height="50"></applet>*/public class Applet04 extends  Applet{public void init() { setBackground(Color.yellow);}public void paint(Graphics g)&nbs

Program with Banner applet in Java

Filed under: Java on 2023-09-20 06:36:06
// Program with Banner applet.import java.awt.*;import java.applet.*;/*<applet code="Applet03" width="300" height="50"></applet>*/public class  Applet03 extends Applet implements Runnable {String msg = "Java Programming Examples";Thread t = null;boolean flag;public void in

Program to use Applet with init(), start() and paint() in Java

Filed under: Java on 2023-09-20 06:35:34
// Program to use Applet with init(), start() and paint().import java.applet.Applet;import java.awt.*;/*<applet  code="AppletTest1.class" width="300" height="100"></applet>*/public class AppletTest1 extends  Applet {String msg = "";public void init() { setBackgro

Program to use Applet Program and it's Life Cycle in Java

Filed under: Java on 2023-09-20 06:34:59
// Program to use Applet Program and it's Life Cycle.import java.awt.*;import java.applet.*;/*<applet code="Applet01" width="300" height="200"></applet>*/public class  Applet01  extends  Applet {public void init() { setBackground(Color.yellow); System.o

Program to use Boolean Wrapper class in Java

Filed under: Java on 2023-09-19 08:09:43
// Program to use Boolean Wrapper classclass  WrapperBoolean{public static void main( String args[ ] ){ Boolean b1 = new Boolean(false); Boolean b2 = new Boolean("true"); System.out.println(b1.booleanValue()); System.out.println(b2.booleanValue());}}Output:falsetrue

Program to use expression with Wrapper classes in Java

Filed under: Java on 2023-09-19 08:09:17
//  Program to use expression with Wrapper classes.class Wrapper5{public static void main(String args[ ]) { Integer iOb = 100; Double dOb = 123.45; dOb = dOb + iOb; System.out.println("dOb after expression: " + dOb);}}Output:dOb after expression: 223.45

Program to use Simple Wrapper Class in Java

Filed under: Java on 2023-09-19 08:07:19
//  Program to use Simple Wrapper Class.class  Wrapper1{public static void main( String args[ ] ){ // Boxing Integer  iOb = new Integer(100); // Unboxing int i = iOb.intValue(); System.out.println(i + " : " + iOb); }}Output:100 : 100

Program to use enum in an application in Java

Filed under: Java on 2023-09-19 08:06:50
//  Program to use enum in an application.import java.util.Random;enum  Answers {NO, YES, MAYBE, LATER, SOON, NEVER}class Question {Random rand = new Random();Answers ask() { int prob = (int) (100 * rand.nextDouble()); if (prob < 15)  return Answers.MAYBE; 

Comparison in Enum example in Java

Filed under: Java on 2023-09-19 06:56:08
// Program to explain that enum has Ordinal// number that is used in comparison.enum  Colour {Red, Green, Blue, Black, White, Orange, Yellow}class  EnumDemo4 {public static void main(String args[ ]){ Colour c1, c2, c3; // Obtain all ordinal values using ordinal(). 

Program to use Java Enum as a Class type in Java

Filed under: Java on 2023-09-19 06:55:19
//  Program to use Java Enum as a Class type.enum Colour {Red(200), Green(150), Blue(100), Black(250), White(175), Orange(225), Yellow(125);private int price;   // price of each colourColour(int p) {  price = p; }int getPrice() {  return price; 

Java Program to use values() and valueOf() methods of Enum

Filed under: Java on 2023-09-19 06:52:39
//  Program to use values() and valueOf() methods of Enum.enum Colour {Red, Green, Blue, Black, White, Orange, Yellow}class EnumDemo2 {public static void main(String args[ ]){ Colour c1;  System.out.println("All Colour constants: "); Colour  clr[ ] = Colour.va

Program to use Enumeration Named Constants in Java

Filed under: Java on 2023-09-19 06:51:52
//  Program to use Enumeration Named Constants.enum Colour {Red, Green, Blue, Black, White, Orange, Yellow}class EnumDemo1 {public static void main(String args[ ]){ Colour c1; c1 = Colour.Red; System.out.println("Value of c1: " + c1); c1 = Colour.Blue; if(c1 =

Chained exception example in Java

Filed under: Java on 2023-09-19 06:50:25
//  Program to explain Chained Exception.class  ChainedException{static void demoproc() { NullPointerException e = new NullPointerException("top layer"); e.initCause(new ArithmeticException("cause")); throw e;}public static void main(String args[ ]) { try 

User defined exception example 2 in Java

Filed under: Java on 2023-09-19 06:50:00
//  Program to create User-defined Exception//  for checking validity of number for Square root.class NegativeNumberException extends Exception {private double num;NegativeNumberException(double n) { num = n;}public String toString() { return "Square root of " + nu

User defined exception example in Java

Filed under: Java on 2023-09-19 06:49:36
// Program to create User-defined Exception// for checking validity of age.class InvalidAgeException extends Exception {private int age;InvalidAgeException(int a) { age = a;}public String toString() { return "Age: " + age + " is not a valid age.";}}class  Exception14&nb

Finally block example in Java

Filed under: Java on 2023-09-19 06:49:11
// Program to use finally Block with exception handling.class  finallyBlockWithException{// Through an exception out of the method.static void procA() { try  {  System.out.println("inside procA");  throw new RuntimeException("demo"); }  finally 

Throw statement example in Java

Filed under: Java on 2023-09-19 06:48:47
//  Program to use throw statement to raise exception and rethrow the exception.class  ThrowExceptionExample {static void demoproc() { try  {  throw new NullPointerException("demo"); }  catch(NullPointerException e)  {  System.out

Nested try catch block with function example in Java

Filed under: Java on 2023-09-19 06:48:23
// Program to explain Nested Try-Catch Block with Function.class  NestedTryCatchWithFunction{static void nesttry(int a) { try  {  if(a==1)    a = a / (a-a);  if(a==2)   {   int c[ ] = { 1 };   c[10] = 100;  } }

Nested try catch block example in Java

Filed under: Java on 2023-09-19 06:47:47
//  Program to explain Nested Try-Catch Block.class NestedTryCatch{public static void main(String args[ ]) { try  {  int a = args.length;  int b = 10 / a;  System.out.println("a = " + a);  try   {    if(a==1)     a 

Order of exception subclass and superclass in Java

Filed under: Java on 2023-09-19 06:47:05
//Program to explain that, when we use multiple catch statements, it is //important to remember that exception subclasses must come before any of their superclasses.class  MultipleException{public static void main(String args[ ]) { try  {  int a = 0;  int b = 

Multiple exceptions in single catch block example in Java

Filed under: Java on 2023-09-19 06:45:58
// Program to catch Multiple exceptions in single Catch Block.class  Exception6{public static void main(String args[ ]) { try  {  int a = args.length;  System.out.println("a = " + a);  int b = 10 / a;  int c[] = { 1 };  c[10] = 100; }  

Multiple catch block example in Java

Filed under: Java on 2023-09-19 06:45:13
// Program to use Multiple Catch Block with Exception.class Exception05 {public static void main(String args[ ]) { try  {  int a = args.length;  System.out.println("a = " + a);  int b = 10 / a;  int c[ ] = { 1 };  c[10] = 100; }  catch

Try and catch example in Java

Filed under: Java on 2023-09-19 06:44:48
//  Simple try and catch example for exception handlingclass  SimpleTryCatchExample {public static void main(String args[ ]) { int d, a; try  {   d = 0;  a = 10 / d;  System.out.println("This will not be printed."); }  catch 

Stack trace of default Exception Handler of JVM

Filed under: Java on 2023-09-19 06:44:23
// Program without Exception Handling and // stack trace of Default Handler of JVM.class  DefaultException2 {static void subroutine() { int d = 0; int a = 10 / d;}public static void main(String args[ ]) { Exception02.subroutine();}}Output:Exception in thread "

Default Exception Handler of JVM

Filed under: Java on 2023-09-19 06:43:44
// Simple  Program without Exception Handling and // use of Default Handler of JVM.class  DefaultException{public static void main(String args[ ]) { int  d = 0; int  a = 10 / d; // here JVM automatiically handle exaception}}Output:Exception in thread "mai

program to explain static import for static Field in Java

Filed under: Java on 2023-09-17 15:41:32
// program to explain static import for static Field.import java.util.Scanner;import static java.lang.Math.PI;class StaticImport2{public static void main( String args[ ] ){ double r, a; Scanner sc = new Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextD

Program to explain static import statement in Java

Filed under: Java on 2023-09-17 15:40:54
//  program to explain static import statement.import static java.lang.Math.*;//   import static java.lang.Math.sqrt;class StaticImport{public static void main( String args[ ] ){ double a = 3.0, b = 4.0; double c = sqrt( a*a + b*b ); System.out.println(" C = " + c );}} 

Import with * sign example in Java

Filed under: Java on 2023-09-17 15:40:07
//  import with * sign.import  java.util.*;class  ImportTest2{public static void main( String args[ ] ){ double r, a; Scanner sc = new Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextDouble();  a = 3.14 * r * r;  Syst

Using class without import in Java

Filed under: Java on 2023-09-17 15:39:27
//  Using class without import.class  ImportTest{public static void main( String args[ ] ){ double  r, a; java.util.Scanner sc = new java.util.Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextDouble();  a = 3.14 * r * r; &n

Using class with import example in Java

Filed under: Java on 2023-09-17 15:38:49
//  Using class with import.import java.util.Scanner;class ImportTest2{public static void main( String args[ ] ){ double r, a; Scanner sc = new Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextDouble();  a = 3.14 * r * r;  Syste

Visibility control in another package example in Java

Filed under: Java on 2023-09-17 15:38:14
// Program to  Visibility Control in Another Package.// First File ( Base.java ) in package p1package  p1;public class  Base {private int n_pri = 1;int n_def = 2;protected int n_pro = 3;public int n_pub = 4;public Base() { System.out.println("base constructor"); Sy

Program to Visibility Control in Same Package example in Java

Filed under: Java on 2023-09-17 15:37:29
// Program to Visibility Control in Same Package.// First File ( Base.java ) in package p1package p1;public class Base {private int n_pri = 1;int n_def = 2;protected int n_pro = 3;public int n_pub = 4;public Base() { System.out.println("base constructor"); System.out.println("n_p

Program to explain Importing Package example in Java

Filed under: Java on 2023-09-17 15:36:40
//  Program to explain Importing Packagepackage MyPack;public class  Balance {String name;double bal;public Balance(String n, double b) { name = n; bal = b;}public void show() { if(bal<0)  System.out.print("--> "); System.out.println(name + ": 

Program to explain Creating Package in Java

Filed under: Java on 2023-09-17 15:36:05
//  Program to explain Creating Package.package MyPack;class  Balance {String name;double bal;Balance(String n, double b) { name = n; bal = b;}void show() { if(bal<0)  System.out.print("--> "); System.out.println(name + ": Rs. " + bal);}}class 

Program to explain Importing Package in Java

Filed under: Java on 2023-09-17 15:35:29
// Program to explain Importing Package.package  Pack1;public class  First{public void view( ){ System.out.println( "This is First Class." );}}// Second File as (ImportPack1.java in current folder) :import Pack1.*;public class  ImportPack1{public static void main( String args[ ] 

Creating package example in Java

Filed under: Java on 2023-09-17 13:20:18
// Program to explain Creating Package.package  Pack1;class First{public void view( ){ System.out.println( "This is First Class." );}}public class  ImportPack2{public static void main( String args[ ] ){ First f = new First(); f.view();}} Output:This is First Class.

Program to Implement a class from multiple interfaces in Java

Filed under: Java on 2023-09-17 13:18:41
// Program to Implement a class from multiple interfaces.interface  A{void showA();}interface  B {void showB();}class  C  implements  A, B{public void showA(){ System.out.println("showA() of A interface.");}public void showB(){ System.out.println("showB() of B

Polymorphism with interface example in Java

Filed under: Java on 2023-09-17 13:17:59
//  Polymorphism  with interface exampleinterface Shape{void draw();}class Rectangle implements Shape{public void draw(){ System.out.println("Drawing Rectangle.");}}class Triangle implements Shape{public void draw(){ System.out.println("Drawing Triangle.");}}class  Polymorph

Program to explain Inheritance of a interface in Java

Filed under: Java on 2023-09-17 13:16:47
//  Program to explain Inheritance of a interface//  from another interface.interface AInterface{void showA();}interface BInterface extends AInterface {void showB();}class Test  implements BInterface{public void showA(){ System.out.println("showA() of A interface.");}public 

Use fields in interface example in Java

Filed under: Java on 2023-09-17 13:15:33
//  Program to use field in interface.interface AInterface{int  SIZE = 100;void  showA();}class Test  implements  AInterface{public void showA(){ System.out.println("showA() of A interface."); System.out.println("SIZE = " + SIZE);}}class  InterfaceTest2{public

Simple interface example in Java

Filed under: Java on 2023-09-17 13:14:57
//  Program to use Simple Interface.interface  AInterface{void showA();}class Test  implements  AInterface{public void showA(){ System.out.println("showA() of A interface.");}}class  InterfaceTest1{public static void main( String args[ ] ){ Test  t1 = new Test

Program to explain final method restricts in Java

Filed under: Java on 2023-09-17 07:10:08
//  Program to explain final method restricts //  (not allow) the overriding of that methodclass  A{final void display(){ System.out.println(" A\'s display().");}}class  B extends A{// final method can't be override.// void display()void show(){ System.out.println(

Program to explain final class restricts (not allow) in Java

Filed under: Java on 2023-09-17 07:09:35
// Program to explain final class restricts (not allow) // the inheritance from that class.final class A{void display(){ System.out.println(" A\'s display().");}}// final class can't be inherited.// class B extends A // Errorclass B{void display(){ System.out.println(" B\'s display().

Program to explain Polymorphism with abstract class in Java

Filed under: Java on 2023-09-17 07:05:35
//  Program to explain Polymorphism with abstract class.abstract class Shape{abstract void draw();}class Rectangle extends Shape{void draw(){ System.out.println("Drawing Rectangle.");}}class Triangle extends Shape{void draw(){ System.out.println("Drawing Triangle.");}}class  Poly

Program to explain Polymorphism in Java

Filed under: Java on 2023-09-17 07:01:53
//  Program to explain Polymorphism or //  Dynamic Method Dispatch or Run Time Binding.class  Shape{void draw(){ System.out.println("Drawing Shape.");}}class  Rectangle extends Shape{void draw(){ System.out.println("Drawing Rectangle.");}}class  Triangle exten

Method overriding example in Java

Filed under: Java on 2023-09-17 07:00:43
// Program to explain Method Overriding.class  A {int  i,  j;A(int a, int b) { i = a; j = b;}void show() { System.out.println("i and j: " + i + " " + j);}}class  B extends A {int  k;B(int a, int b, int c) { super(a, b); k = c

Method Overloading example in Java

Filed under: Java on 2023-09-17 07:00:19
// Program to explain Method Overloading.class  A {int i, j;A(int a, int b) { i = a; j = b;}void show() { System.out.println("i and j: " + i + " " + j);}}class  B extends A {int k;B(int a, int b, int c) { super(a, b); k = c;}void show(Strin

Hierarchical inheritance example in Java

Filed under: Java on 2023-09-17 06:58:31
//  hierarchical inheritance exampleclass student1{   private String name;   private int rno;      void setname(String name, int rno)   {       this.name = name;       this.rno = rno;   }  &

Use of super keyword to call super class constructor in Java

Filed under: Java on 2023-09-17 06:57:43
// Program to use super keyword to call Super class constructor to // initialize super class instance variablesclass Box {private double width;private double height;private double depth;Box(Box ob) {  width = ob.width; height = ob.height; depth = ob.depth;}Box(doub

Use of this keyword example in Java

Filed under: Java on 2023-09-17 06:56:56
//  Program to use this keywordclass n {   public int i;   int getI() {       return i;   }}class M extends n {   int a, b;   void sum(int a, int b) {       int d = getI();       this.a

Multilevel inheritance example in Java

Filed under: Java on 2023-09-17 06:56:32
//  Program to explain Multilevel Inheritance.class Box {private double width;private double height;private double depth;Box(Box ob) {  width = ob.width; height = ob.height; depth = ob.depth;}Box(double w, double h, double d) { width = w; height = h;

Simple Inheritance Example 2 in Java

Filed under: Java on 2023-09-17 06:56:01
// Simple Inheritance example 2class  A {int i, j;void showij() { System.out.println("i and j: " + i + " " + j);}}class B extends A {int k;void showk() { System.out.println("k: " + k);}void sum() { System.out.println("i+j+k: " + (i+j+k));}}class  Inh

Simple Inheritance Example in Java

Filed under: Java on 2023-09-17 06:55:33
// Simple Inheritance examplepublic class SimpleInheritance{   public static void main(String[] args) {       SubClass ob1 = new SubClass();       ob1.showmsgSuper();       ob1.showmsgSub();   }}class SuperClass{  &

Array of String Example in Java

Filed under: Java on 2023-09-17 06:55:03
// Program to explain the concept of "ARRAY OF STRING".class  StrArray{public static void main( String args[ ] ){ final int days = 7; String str[ ] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"   };   for( int  j=0 ; j<day

stringBuffer reverse () method example in Java

Filed under: Java on 2023-09-17 06:54:31
// Program to explain the following StringBuffer function :// StringBuffer reverse()class  Mreverse{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = " + sb );  sb.reverse(); Sys

stringBuffer replace () method example in Java

Filed under: Java on 2023-09-17 06:53:46
// Program to explain the following StringBuffer function :// StringBuffer replace( int startIndex, int endIndex, String str )class  Mreplace1{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = 

stringBuffer insert(index, obj) function example in Java

Filed under: Java on 2023-09-17 06:53:13
// Program to explain the following StringBuffer function :// StringBuffer insert( int index, Object ob )class  Minsert1{public static void main(String args[ ]){ StringBuffer sb = new StringBuffer(40); sb = sb.insert(0, 'A'); System.out.println(" String 1 = " + sb);  sb

stringBuffer insert() method example in Java

Filed under: Java on 2023-09-17 06:52:17
// Program to explain the following StringBuffer function :// StringBuffer insert( int index, String str )class  Minsert{public static void main( String args[ ] ){ String s = new String( "Java" ); StringBuffer sb = new StringBuffer( " Examples." ); sb = sb.insert( 0, s ); Sy

stringBuffer deleteCharAt() method in Java

Filed under: Java on 2023-09-17 06:51:38
// Program to explain the following StringBuffer function :// StringBuffer deleteCharAt( int loc )class  MdeleteCharAt{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = " + sb );  sb 

stringBuffer delete function in Java

Filed under: Java on 2023-09-17 06:51:06
// Program to explain the following StringBuffer function ://StringBuffer delete( int startIndex, int endIndex )class  Mdelete{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = " + sb ); &

toString() method in spring buffer in Java

Filed under: Java on 2023-08-23 18:58:36
// Program to explain the following StringBuffer function ://String toString()class  MtoString{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." );  String s = sb.toString(); System.out.println( " String = " + s );&nb

subString() method example in stringBuffer in Java

Filed under: Java on 2023-08-23 18:57:52
// Program to explain the following StringBuffer function ://String substring( int startIndex )//String substring( int startIndex, int endIndex )class  Msubstring1{public static void main( String args[ ] ){ StringBuffer sb1 = new StringBuffer( "Java Programming Examples." );  Sys

setLength() method example in Java

Filed under: Java on 2023-08-23 18:57:03
// Program to explain the following StringBuffer function :// void setLength( int len )class  MsetLength{public static void main(String args[ ]){ StringBuffer sb1 = new StringBuffer("Java Programming Examples."); System.out.println(" String = " + sb1); sb1.setLength(12); Sys

Use of setCharAt() method in Java

Filed under: Java on 2023-08-23 18:56:33
// Program to explain the following StringBuffer function :// void setCharAt( int where, char ch )class  MsetCharAt1{public static void main( String args[ ] ){ StringBuffer sb1 = new StringBuffer( "Java Nrogramming Examples." ); System.out.println( " String Before Replacing = " + sb1 

capacity() method example in Java

Filed under: Java on 2023-08-23 18:56:04
// Program to explain the following StringBuffer function :// int capacity()class  Mcapacity{public static void main( String args[ ] ){ StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer( "Java Programming Examples" ); System.out.println( " Capacity = " + 

stringBuffer append example in Java

Filed under: Java on 2023-08-23 18:55:29
// Program to explain the following StringBuffer function :// StringBuffer append( char c )class  Mappend1{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( 40 ); sb = sb.append( 'J' ); System.out.println( " String 1 = " + sb );  sb.append( 

stringBuffer() example in Java

Filed under: Java on 2023-08-23 18:54:55
// Program to explain the following StringBuffer function :// StringBuffer()// StringBuffer( int size )// StringBuffer( String str )class  MStringBuffer1{public static void main(String args[ ]){ StringBuffer sb = new StringBuffer("Java");  System.out.println(" sb = " + sb ); 

lastIndexOf() method example in Java

Filed under: Java on 2023-08-23 18:54:29
// Program to explain the following String function :// int lastIndexOf( String str )class  MlastIndexOf{public static void main( String args[ ] ){ String s1 = "Java Programming Examples Java Programming Examples.";    System.out.println( " Last Index of " + 'P' + " = " + s1

index of() method example in Java

Filed under: Java on 2023-08-23 18:54:04
// Program to explain the following String function :// int indexOf(int ch) // int indexOf( String str )class  MindexOf{public static void main(String args[ ]){ String s1 = "Java Programming Examples Java Programming Examples.";    System.out.println(" Index of " + 'P' 

subString() method example in Java

Filed under: Java on 2023-08-23 18:53:38
// Program to explain the following String function :// String substring( int startIndex )// String substring( int startIndex, int endIndex )class  Msubstring{public static void main( String args[ ] ){ String s1 = "Java Programming Examples.";   String s2 = s1.substring( 5 )

valueOf() method example in Java

Filed under: Java on 2023-08-23 18:53:00
//  Program to explain the following String function ://  static String valueOf( double num )class  MvalueOf {public static void main( String args[ ] ){ char  ch[ ] = { 'J', 'A', 'V', 'A' }; String s1 = String.valueOf( ch ); System.out.println( " String 1 : " 

trim() method example in Java

Filed under: Java on 2023-08-23 18:52:29
// Program to explain the following String function :// String  trim()class  Mtrim{public static void main( String args[ ] ){ String s = "            Java Programming Examples.           ".trim(); System.out.print( "String af

toUpperCase() method example in Java

Filed under: Java on 2023-08-23 18:51:59
// Program to explain the following String function :// String toUpperCase()class  MtoUpperCase{public static void main( String args[ ] ){ String s1 = "Java Programming Examples"; String s2 = s1.toUpperCase(); System.out.println( " Original  String : " + s1 ); System.ou

toLowerCase() method example in Java

Filed under: Java on 2023-08-23 18:51:33
// Program to explain the following String function : // String toLowerCase()class  MtoLowerCase{public static void main( String args[ ] ){ String s1 = "Java Programming Examples."; String s2 = s1.toLowerCase(); System.out.println( " Original  String : " + s1 ); Sy

split() method example in Java

Filed under: Java on 2023-08-23 18:51:06
// Program to explain the following String function :// String[ ] split( Stirng regExp )class  Msplit{public static void main( String args[ ] ){ String s1 = new String( "Java Programming Examples" ); String s2[ ] = s1.split( " " ); System.out.println( " String = " + s2[0] ); 

regionMatches() method example in Java

Filed under: Java on 2023-08-23 18:50:39
// Program to explain the following String function :// boolean regionMatches( int startIndex,// String str2, int str2StartIndex, int numChars )class  MregionMatches1 {public static void main(String args[ ]){ boolean b,b1; String s1 = new String("Java Programming Examples.");&nbs

getChars() method example in Java

Filed under: Java on 2023-08-23 18:49:57
// Program to explain the following String function :// void getChars( int sourceStart, int sourceEnd,// char target[], int targetStart )class  MgetChars{public static void main( String args[ ] ){ char  ch[ ] = new char[4]; String s1 = "Java Programming Examples.";  &nb

compareTo() method example in Java

Filed under: Java on 2023-08-23 18:49:18
// Program to explain the following String function :// int compareTo( String str )class  McompareTo{public static void main( String args[ ] ){ String s1 = "JAVA"; String s2 = "JAVA"; String s3 = "Java";    System.out.println( s1 + " compared to " + s2 + " = " + s1

Difference between equals and == operator in Java

Filed under: Java on 2023-08-23 18:48:34
// Program to explain the following String function :// equals versus ==class  MequalsVersusEqualto{public static void main( String args[ ] ){ boolean b; String s1 = "JAVA"; String s2 = "JAVA"; String s3 = "Java"; String s4 = new String( "JAVA" ); String s5 = new S

equalsIgnoreCase() function example in Java

Filed under: Java on 2023-08-23 18:47:45
// Program to explain the following String function :// boolean equalsIgnoreCase( Object str )class  MequalsIgnoreCase{public static void main( String args[ ] ){ String s1 = "JAVA";  String s2 = "JAVA"; String s3 = "Java"; System.out.println( s1 + " equals " + s2 + " = 

length() function example in Java String

Filed under: Java on 2023-08-23 06:58:27
// Program to explain the following String function :// int length()class  Mlength{public static void main( String args[ ] ){ char ch[ ] = { 'J', 'A', 'V', 'A' }; String s1 = new String( ch ); System.out.println( " String = " + s1 ); System.out.println( " Length = " + s1.len

Java Program to use charAt function in string

Filed under: Java on 2023-08-23 06:57:40
// Program to explain the following String function :// char charAt( int where )class  McharAt{public static void main( String args[ ] ){ char ch; String s1 = "Nils";   ch = s1.charAt( 0 ); System.out.println( " Character at 0 : " + ch ); ch = "Java".charAt( 3

Make string using ASCII value in Java

Filed under: Java on 2023-08-23 06:57:05
// Program to explain the following String function :// String( byte asciiChars[ ] )class  MString4{public static void main( String args[ ] ){ char ch[ ] = { 'J', 'A', 'V', 'A' }; String s1 = new String( ch ); byte b[ ] = { 65, 66, 67, 68, 69, 70 }; String s2 = new String( b

Simple string function example in Java

Filed under: Java on 2023-08-23 06:56:05
// Program to explain the following String function :// String(char chars[ ], int startIndex, int numChars)class  MString2{public static void main( String args[ ] ){ char ch[ ] = { 'J', 'A', 'V', 'A' }; String s = new String( ch, 2, 2 ); System.out.println( " String = " + s );&nb

Simple string example in Java

Filed under: Java on 2023-08-23 06:55:35
// Program to explain the following String function :// String( String strObj )class  MString11{public static void main( String args[ ] ){ String s1 = "Nils : " + 5 + 5;  String s2 = "Nils : " + (5 + 5); System.out.println( s1 ); System.out.println( s2 );}}Output:Nils :

Initialise 2D array in Java

Filed under: Java on 2023-08-23 06:54:46
// Program to initialize 2D array with expressionclass  InitTwoDWithExp {public static void main(String args[ ]) { double a[ ][ ] = {   { 0*0, 1*0, 2*0, 3*0 },   { 0*1, 1*1, 2*1, 3*1 },   { 0*2, 1*2, 2*2, 3*2 },   { 0*3, 1*3, 2*3, 3*3 } };&

Jagged array example in Java

Filed under: Java on 2023-08-23 06:54:05
//  Program to explain Jagged Arrayclass  JaggedArray2 {public static void main(String args[ ]) { int ar[ ][ ] = new int[4][ ]; ar[0] = new int[1]; ar[1] = new int[2]; ar[2] = new int[3]; ar[3] = new int[4]; int  i, j, x = 1; for( i=0 ; i &

Jav Program to find sum of two matrices

Filed under: Java on 2023-08-23 06:53:38
// Program to addition of two Matrixclass  MatrixAddition{public static void main( String args[ ] ){ int  i, j; int  c[ ][ ] = new int[3][3];  int  a[ ][ ] = {      {1, 2, 3},     {4, 5, 6},     {7, 8, 9}  };&n

Transpose of the array in Java

Filed under: Java on 2023-08-23 06:51:24
//Program to find transpose of the Matrixclass  MatrixTranspose{public static void main( String args[ ] ){ int i, j; int  b[ ][ ] = new int[3][3];  int   a[ ][ ] = {      {1, 2, 3},    {4, 5, 6},      {7, 8, 9}  }; 

Matrix of array example in Java

Filed under: Java on 2023-08-23 06:50:50
// print simple matrix of arraypublic class PrintingInMatrixFormat{   public static void main(String[] args)   {       int i,j;       int a[][]=new int[3][3];       a[0][0]=10;       a[0][1]=20; 

Iterate 2D array in Java

Filed under: Java on 2023-08-23 06:49:05
// Program to use Two dimensional Arrayclass TwoDArray {public static void main(String args[ ]) { int a[ ][ ]= new int[2][3]; int i, j, x = 1; for(i=0; i<2; i++) {  for(j=0; j<3; j++)   {   a[ i ][ j ] = x;   x++;  } }&

Program for Sum of 2D array elements in Java

Filed under: Java on 2023-08-23 06:48:23
// Sum Of Array Elementspublic class SumOfArrayElements{   public static void main(String[] args) {       int i, j, sum = 0;       int a[][] = {{10, 20, 30}, {40, 50, 60}, {70, 80, 90}};       for (i = 0; i < 3; i++) {  &n

Merge sort example in Java

Filed under: Java on 2023-08-23 06:47:40
// Program to Implement Merge Sortimport java.util.Scanner;public class MergeSort {   /* Merge Sort function */   public static void sort(int[] a, int low, int high)    {       int N = high - low;           &nb

Quick sort example in Java

Filed under: Java on 2023-08-23 06:47:20
// Java Program to Implement Quick Sortimport java.util.Scanner; public class QuickSort {   /** Quick Sort function **/   public static void sort(int[] arr)   {       quickSort(arr, 0, arr.length - 1);   }   /** Quick so

Selection sort example in Java

Filed under: Java on 2023-08-23 06:46:58
// Program to SORT the Array elements using SELECTION SORTclass  SelectionSort{public static void main( String args[ ] ){ int  i, j; int  a[ ] = { 40, 20, 50, 10, 30 };  System.out.print( "\n Unorted Numbers are = " ); for( i=0 ; i<5 ; i++ ) {  Sy

Insertion sort example in Java

Filed under: Java on 2023-08-23 06:46:38
//  Program to SORT the Array elements using INSERTION SORTclass  InsertionSort{public static void main( String args[ ] ){ int  a[ ] = { 0, 20, 40, 10, 50, 30 }; int i, n = 5; System.out.print( " The Unsorted Array is = " ); for( i=1 ; i<=n ; i++ ) {  

Bubble sort example in java

Filed under: Java on 2023-08-23 06:46:12
// Program to SORT the Array elements using BUBBLE SORTclass  BubbleSort{public static void main( String args[ ] ){ int i, j, t; int  a[ ] = { 40, 20, 50, 10, 30 };  System.out.print( "\n Unorted Numbers  are = " ); for( i=0 ; i<5 ; i++ ) {  Syste

Fibonacci series using Array in Java

Filed under: Java on 2023-08-23 06:45:49
//  Program to Print the Fibonacci Series using Array.class  FiboArray{public static void main( String args[ ] ){ int n, i; int  a[ ] = new int[20];   n = 10; a[0] = 0;   a[1] = 1;   for(i=2 ; i<n ; i++)    {  a[

Program to arrange array in Ascending order in Java

Filed under: Java on 2023-08-19 18:39:56
// Arrange Array in Ascending orderpublic class ArrayAscending {   public static void main(String[] args) {       int i, temp, j;       int a[] = {1, 7, 5, 9, 2, 12, 53, 25};System.out.println("Before Ascending order:");for (i = 0; i < 8; i++) {&n

Read array from keyboard in Java

Filed under: Java on 2023-08-19 18:38:03
//  Read array from keyboardimport java.util.*;class  ArrayTest{public static void main( String args[ ] ){ Scanner sc = new Scanner( System.in ); int  i; int  a[ ] = new int[5];  for( i=0 ; i<5 ; i++ ) {  System.out.print( "Enter Value : " );

Simple static Array example in Java

Filed under: Java on 2023-08-19 18:36:19
// Simple static arraypublic class SimpleArray{   public static void main(String[] args)    {       int a[]={10,20,30,40,50};       for(int i=0;i<5;i++)       {           System.out.

How to Add Jar Files in Library of project in IntelliJ Idea

Filed under: Java on 2023-08-19 13:09:43
Hello Developers, If you stuck to find how to add jar files in library of your project in IntelliJ Idea follow below steps:Open your IntelliJ idea and open the project on which you are working.You will see a setting icon on top right corner of your screen. Click on that and select project struc

Do while Loop example in Java

Filed under: Java on 2023-08-18 07:00:44
// Do while exampleclass  DoWhileTest{public static void main( String args[ ] ){ int   i = 1; // 1.  Initialization do {  System.out.print( "  " + i );  i++; // 3.  Increment. }while ( i <= 5 ); // 2.  Test / Condition}}Output: 1 &n

Program to check Armstrong number in Java

Filed under: Java on 2023-08-18 07:00:21
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.Code// Program to check whether a given Number is// ArmStrong Number or not.class  ArmstrongTest{p

Program to find Strong number in Java

Filed under: Java on 2023-08-18 06:59:13
What is strong number?Strong number is a special number whose sum of the factorial of digits is equal to the original number. For Example: 145 is strong number. Since, 1! + 4! + 5!Code//Program to Check the given Number is STRONG Number or not.// Logic 145 = 1! + 4! + 5!  (i.e.,  145 = 1 +

Program to check palindrome number in Java

Filed under: Java on 2023-08-18 06:57:33
// check given number is palindrom or notpublic class PalindromeNumber {   public static void main(String[] args) {       int n = 1215;       int sum = 0;       int m = n;       while (n > 0) {    

Count number of digits in any given number in Java

Filed under: Java on 2023-08-18 06:55:39
// count number of given digitsclass  NumberOfDigits{public static void main( String args[ ] ){ int n, c;  n = 1234; c = 0; while( n != 0 ) {  n = n / 10;  c++; } System.out.println( " Number of Digits : " + c );}}Output:Number of Digits : 4

Nested while Loop example in Java

Filed under: Java on 2023-08-18 06:54:55
// Nested while loop examplepublic class NestedWhile{   public static void main(String[] args) {       int a = 1, b;       while (a <= 5) {           b = 1;           while (b <= a) {&

While Loop Example in Java

Filed under: Java on 2023-08-18 06:54:25
// simple while loop examplepublic class WhileLoop{   public static void main(String[] args) {       //learning       int a = 1;       while (a <= 5) {           System.out.println(" "+a);  &n

For each loop example 2 in Java

Filed under: Java on 2023-08-18 06:53:53
// for each loop exampleclass  ForEachTest {public static void main( String args[ ] ){  int  ar[ ] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };   for(int  x : ar)    { System.out.print(x + " ");  x = x * 10;  // no effect on num

For each loop example in Java

Filed under: Java on 2023-08-18 06:53:12
// foreach examplepublic class ForEachLoop {   public static void main(String[] args) {       int arrayname[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21};//learn       for (int val : arrayname) {           System.out.print

Advance for loop example in Java

Filed under: Java on 2023-08-18 06:52:19
public class AdvancedForLoop {   public static void main(String[] args) {             String s1 = "INDIA";       char s2[] = new char[s1.length()];       for (int i = 0; i < s1.length(); i++) {    

Program to find HCF and LCM of two numbers in Java

Filed under: Java on 2023-08-18 06:51:38
 // Program to find HCF and LCM of Two given Number.import java.util.Scanner;class  HcfAndLcmExample{public static void main( String args[ ] ){ int a, b, i, s, hcf=0, lcm=0; Scanner sc = new Scanner( System.in );  System.out.print( " Enter First Number : " ); a = s

Program to check Prime Number using for loop in java

Filed under: Java on 2023-08-18 06:50:30
// Program to Check the Given Number is PRIME or NOT.class  PrimeTest{public static void main( String args[ ] ){ int i, n; boolean  flag = true;  n = 29;   for( i=2 ; i<=n/2 ; i++ ) {  if( n % i == 0 )  {   flag = false;   

Program to check whether given number is Perfect or not in Java

Filed under: Java on 2023-08-18 06:49:47
Before proceeding to our program code, we must see what is perfect number.What is perfect number?In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 

Program to Print Lucas series in Java

Filed under: Java on 2023-08-18 06:46:47
// Program to Print the Lucas Series.//  1  1  1  3  5  9.....n  Terms.class  LucasTest {public static void main( String args[ ] ){ int n, i , a = 1, b = 1, c = 1, d;   n = 10; System.out.print( " " + a + " " + b + " " + c);  

Print Fibonacci numbers example using Java

Filed under: Java on 2023-08-18 06:46:16
//  Program to Calculate the Fibonacci Series of the Given Number.class  FibonacciTest {public static void main( String args[ ] ){ int n, i , a = 0, b = 1, c = 0;   n = 6; System.out.print( " " + a + " " + b );    for( i=1 ; i<=(n-2) ; i++ )&

Program for getting Factorial of any number in Java

Filed under: Java on 2023-08-18 06:45:28
//Program to Calculate the Factorial of the Given Number.class  FactorialTest{public static void main( String args[ ] ){ int i, n;  n = 5; int f = 1; for( i=n ; i>=1 ; i-- ) {  f = f * i ; } System.out.println( "\n The Factorial of " + n + " is = 

Continue statement example in Java

Filed under: Java on 2023-08-18 06:44:47
// continue staement examplepublic class ContinueStatement{   public static void main(String[] args) {       for (int i = 0; i < 10; i++) {                       if (i % 2 == 0) {        

Label block and break example in Java

Filed under: Java on 2023-08-18 06:44:16
//  Label block and breakpublic class BreakAsGoto{   public static void main(String[] args) {       aBlock:       {           bBlock:           {           

Break statement example in Java

Filed under: Java on 2023-08-18 06:43:35
// Break startment in for loop examplepublic class BreakStatement{   public static void main(String[] args) {       for (int i = 0; i < 10; i++) {           System.out.println(i);           if(i==5){  &

Square Pattern of star logic in Java

Filed under: Java on 2023-08-18 06:42:50
//pattern using for and whilepublic class ForPattern{   public static void main(String[] args) {       int i, j;       for (i = 1; i <= 5; i++) {           for (j = 1; j <= 5; j++) {        &nbs

Print star Patter 2 logic in Java

Filed under: Java on 2023-08-18 06:42:09
// for loop and while looppublic class ForWhile {   public static void main(String[] args) {       for (int i = 1; i <= 5; i++) {           int j = i;           while (j <= 5) {       

Print star patter 1 logic in Java

Filed under: Java on 2023-08-18 06:38:27
// For loop patternpublic class NestedFor {   public static void main(String[] args) {       for (int i = 0; i < 5; i++) {           for (int j = 0; j <= i; j++) {               System.out.print

Sum of Even and Odd using For Loop in Java

Filed under: Java on 2023-08-18 06:37:55
This program will print sum of Even numbers and odd numbers separately.// sum of even odd using while loopclass OddEvenSum {   public static void main(String[] args) {       int i;       int sum = 0;       int sum1 = 0;  &nbs

Get Sum of n numbers using For Loop in Java

Filed under: Java on 2023-08-18 06:36:56
This program will print the sum of n numbers. // sum of numbers using command lineclass  ArguSum{   public static void main( String args[ ] )   { int  s = 0, len; len = args.length;  for( int i=0 ; i<len ; i++ ) {  int  x = Int

Simple for loop example in Java

Filed under: Java on 2023-08-18 06:35:54
Here we have made a simple for loop example in Java.// Simple for loop examplepublic class ForLoop{   public static void main(String[] args) {       for (int i = 0; i < 5; i++) {           System.out.println("Loop : "+i);    &n

String Literal in case of Switch in Java

Filed under: Java on 2023-08-12 20:54:23
//  Program to use String literal in case of switch-case statementimport java.util.*;class  SwitchString{public static void main(String args[ ]){ String dname; Scanner sc = new Scanner( System.in );  System.out.print( " Enter Day Name = " ); dname = sc.next(); 

Type of byte using Switch case in Java

Filed under: Java on 2023-08-12 20:53:15
// Switch case examplepublic class SwitchCase{   public static void main(String[] args) {       int choice = 1;       switch (choice) {           case 0:               System.out.p

Find Odd Even using Switch statement in Java

Filed under: Java on 2023-08-12 20:52:05
// Even odd using switch caseclass  EvenOdd{public static void main(String args[ ]){ for( int i=1 ; i<=10 ; i++ ) {  switch( i )  {   case 1:   case 3:   case 5:   case 7:   case 9:    System.out.println( i + " -

Find Day by day number using switch statement in Java

Filed under: Java on 2023-08-12 20:51:13
// Find day using switch caseclass  SwitchCaseDays {public static void main(String args[ ]){ int day; day = 6; switch( day ) {  case 1:   System.out.println( " Monday." );   break;  case 2:   System.out.println( " Tuesday." );&nbs

Simple Switch case example in Java

Filed under: Java on 2023-08-12 20:50:25
// Simple switch case exampleclass SwitchDemo {public static void main( String args[ ] ){ int  a = 2;  switch (a)  {  case 1 :   System.out.println("One.");   break;  case 2 :   System.out.println("Two.");   break;&

Simple program to check day by day number using if elsein Java

Filed under: Java on 2023-08-12 20:48:24
// Program to show Day Name according to Day Number ( 1 - 7 ) using else-if ladder statement.class  ElseIfDays{public static void main(String args[ ]){ int day; day = 7; if( day == 1 )  System.out.println( " Monday." ); else if( day == 2 )  System.out.println( " Tu

Program to find leap year in Java

Filed under: Java on 2023-08-12 20:46:26
// Program to find given year is leap year or notclass  Leap2{public static void main( String args[ ] ){ int y; y = 2016; if( y % 100 == 0 ) {  if( y % 400 == 0 )   System.out.println( " It is a LEAP Year." );  else   System.out.println( " It is

Nested if-else example in Java

Filed under: Java on 2023-08-12 20:44:38
// Program to find Maximum of Three numbers using Nested-If.class Max3IfElse{public static void main( String args[] ){ int a, b, c, max; a = 23; b = 93; c = 10; if( a > b ) {  if( a > c )   max = a;  else   max = c;     

Nested if example in Java

Filed under: Java on 2023-08-12 20:43:55
//  Nested if examplepublic class NestedIf{  public static void main(String[] args) {  int a = 10;    if(a>0){      if(a<=10){          System.out.println("a --> 0 to 10");      }      &

Program to find Odd Even in Java

Filed under: Java on 2023-08-12 20:42:38
// Simple if else to find even odd numberclass EvenOddTest{public static void main( String args[] ){ int n; n = 23; if( n % 2 == 0 )  System.out.println("Number " + n + " is Even Number." ); else  System.out.println("Number " + n + " is Odd Number." );}}Output:Number 23

Program to Find maximum number in Java

Filed under: Java on 2023-08-12 20:42:01
// Simple if else examplepublic class IfElse{   public static void main(String[] args)    {      int a = 23, b = 47, c;        if(a>b)      {          System.out.println("a is greater than b")

If else example in Java

Filed under: Java on 2023-08-12 20:41:06
//  Simple if else exampleclass IfElse{public static void main( String args[ ] ){ int  n;  n = 23; if( n > 100 ) {  System.out.println( " The number is greater than 100." ); }  else {  System.out.println( " The number is smaller tha

Simple If statement example in Java 2

Filed under: Java on 2023-08-12 20:40:31
// Simple if examplepublic class SimpleIf{   public static void main(String[] args) {       int a = 10;       int b = 20;              if(a>b){           System.out.println("a i

Simple If statement example in Java

Filed under: Java on 2023-08-12 20:39:45
// Simple if exampleclass  SimpleIf{public static void main(String args[ ] ){ int  n;  n = 230; if( n > 100 ) {  System.out.println( " The number is greater than 100." ); }}}Output:The number is greater than 100.

Program to explain Implicit in Java

Filed under: Java on 2023-08-11 19:33:38
// Program to explain Implicit Conversion ( Automatic Type Conversion )class ImplicitConversion{public static void main( String args[ ] ){ Int  i = 2; float  f = 12.33f; byte  b = 1;  double d = 124.097; double  res = ( i - b ) * ( d / f );  &nb

Type Casting Example in Java

Filed under: Java on 2023-08-11 19:32:57
//  Program to explain Type Casting ( Explicit Conversion )class TypeCasting{public static void main( String args[ ] ){ int a; float b = 123.333f; System.out.println( " Before Casting = " + b ); a = (int) b;  System.out.println( " After Casting  = " + a );}}Ou

Program to use Short-Hand Assignment Operators in Java

Filed under: Java on 2023-08-11 19:32:24
//  Program to use Short-Hand Assignment Operators ( +=, -=, *=, /=, %= )class ShortHandAssign {public static void main(String args[ ]) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6; System.out.println("a = " + a); S

Conditional Operators Examples 2 in Java

Filed under: Java on 2023-08-11 19:28:21
// Program to find the Largest of three given numbers using Conditional Operatorclass MaxOf3ConditionalOperator{public static void main( String args[ ] ){ int a, b, c, max = 0; a = 20; b = 30; c = 45;    max = ((a>b) ? ((a>c) ? a : c ) : ((b>c) ? b : c )); 

Conditional Operators Examples in Java

Filed under: Java on 2023-08-11 19:27:39
//Program to explain the concept of Conditional Operator in different styleclass ConditionalOperator{public static void main( String args[ ] ){       int a, b, max; a = 25; b = 14; max = ( ( a > b ) ? a : b ); System.out.print("\nMaximum Value is= " + max )

Boolean Logical Operator Example in Java

Filed under: Java on 2023-08-11 19:26:51
//  Program to use Boolean Logical Operators ( &, |, ^, !  )class  BoolLogic {public static void main(String args[ ]) { boolean a = true; boolean b = false;  boolean c = a | b; boolean d = a & b; boolean e = a ^ b; boolean f = !a;&n

Modulus Operator example in Java

Filed under: Java on 2023-08-11 19:26:14
// Program to use Modulus  operator ( % )class Modulus {public static void main(String args[ ]) { int x = 42; double y = 42.25; System.out.println("x mod 10 = " + x % 10); System.out.println("y mod 10 = " + y % 10);}}Output:x mod 10 = 2 y mod 10 = 2.25

Decrement Operator example in Java

Filed under: Java on 2023-08-11 19:25:39
// Decrement Operator Exampleclass DecrementOperatorExample{public static void main( String args[ ] ){ int a = 10, b = 20 ,c;  c = ( --a ) + ( --b ); //c = ( a-- ) + ( b-- );  System.out.println( " Value of a = " + a ); System.out.println( " Value of b = " + b );&n

Increment Operator Example in Java

Filed under: Java on 2023-08-11 19:25:04
// Increment Operator exampleclass  IncrementOperatoeExample{public static void main( String args[ ] ){ int a = 10, b = 20 ,c;  c = ( ++a ) + ( ++b );  // a++ is Post fix increment // ++b is pre fix increment  System.out.println( " Value of a = " + a );&n

Logical Bitwise Operators Examples in Java

Filed under: Java on 2023-08-11 19:24:32
//Program to use Logical Bitwise Operatorsclass BitwiseOperatorExample{public static void main(String args[ ]) { int a = 3, b = 6, c; System.out.println("a = " + a); System.out.println("b = " + b); c = a & b; System.out.println("a & b = " + c);  c = a 

Relational Operators Examples in Java

Filed under: Java on 2023-08-11 19:23:40
// Program to explain the working of Relational Operatorsclass RelationalOpr{public static void main( String args[ ] ){ int a = 20, b = 10; System.out.println( " a = " + a ); System.out.println( " b = " + b ); System.out.println( " a < b = " + ( a < b ) ); System.out.p

Arithmetic Operators Examples In Java

Filed under: Java on 2023-08-11 19:23:00
// Arithmetic Operator Exampleclass ArithOpr{public static void main( String args[ ] ){ int a = 25, b = 10; float c = 25.5f, d = 4.0f; System.out.println( " a = " + a ); System.out.println( " b = " + b ); System.out.println( " c = " + c ); System.out.println( " d = " + 

Exit() function example in Java

Filed under: Java on 2023-08-11 19:21:52
// Program to use exit() functionclass ExitTest{public static void main( String args[] ){ int a = 10; System.out.println( "AAA" ); if( a == 10 )  System.exit(0); System.out.println( "BBB" );}}Output:AAA

Use of Return in Java

Filed under: Java on 2023-08-11 19:21:20
// Program to use of retuen statementclass ReturnTest{public static void main( String args[] ){ int a = 10; System.out.println( "Before return." ); if( a == 10 )  return; System.out.println( "After return." );}} Output:Before return.

Take Input from User by Using Scanner Class in Java

Filed under: Java on 2023-08-11 19:20:37
This program will show how to use scanner class to take user input.//  Scanner exampleimport java.util.Scanner;class ScannerExample{public static void main( String args[ ] ){ Scanner sc = new Scanner( System.in ); int n;  System.out.print( "Enter a Number : "); n = sc.n

Simple Sum Program Using Windows Command in Java

Filed under: Java on 2023-08-11 19:19:25
// Simple sum example using command lineclass  Sum{public static void main( String args[ ] ){ int  num1, num2, sum; num1 = Integer.parseInt( args[0] ); num2 = Integer.parseInt( args[1] ); sum = num1 + num2; System.out.println( " Sum = " + sum );}}Output: (In comman

Take Input from User through Console in Java

Filed under: Java on 2023-08-11 19:18:43
// Input using Console Exampleimport java.io.*;class ConsoleExample{public static void main( String args[ ] ){ Console cn = System.console(); int n;  System.out.print( "Enter a Number : "); n = Integer.parseInt( cn.readLine() ); System.out.println( "The given number : "

Java Program to convert days into Year, Month, Day

Filed under: Java on 2023-08-11 19:17:44
// Program to convert Total Number of Days into Years, Months, Weeks and remaing days.class  Days{public static void main( String args[ ] ){   int  days, years, months, weeks;   days = 1050; years = days / 365;   days = days % 365;   months

Swapping of Variables without using Third Variable in Java

Filed under: Java on 2023-08-11 19:16:47
// Swapping example without third variableclass SwapWithoutThirdVariable{public static void main( String args[ ] ){ int   a, b; a = 10; b = 20; System.out.print("\nBefore Swapping : " ); System.out.print( a + "   " + b ); a = a + b; b = a - b; a = a 

Swaping of Variables using third Variable in Java

Filed under: Java on 2023-08-11 19:16:00
// Swapping example using third variableclass  Swap{public static void main( String args[ ] ){ int  a, b, t; a = 10; b = 20;  System.out.print( "\nBefore Swapping :" ); System.out.print( a + "   " + b ); t = a; a = b; b = t;  Syst

Declare variable at the end of Java Program

Filed under: Java on 2023-08-11 19:15:13
// declare variable at endclass  DeclareAtEnd{public static void main( String args[ ] ){ msg = "Hello Java Developer..!";       System.out.println("Message : " + msg);}static String msg;}Output:Message : Hello Java Developer..!

How to create Local Constant in Java

Filed under: Java on 2023-08-11 19:14:15
// Program to using final variable within method// to create local constant.class  FinalVar1{public static void main( String args[ ] ){ double r = 10.0, a; final double PI = 3.14159; a = PI * r * r; System.out.println("Area of Circle : " + a);}}Output:Area of Circle : 314.15

Final Variable Example in Java

Filed under: Java on 2023-08-11 19:12:59
//  Program to use final variable to Create constant.class  FinalVar{final static double PI = 3.14159;public static void main( String args[ ] ){ double r = 10.0, a; a = PI * r * r; System.out.println("Area of Circle : " + a);}}Output:Area of Circle : 314.159

Constants in Java

Filed under: Java on 2023-08-11 19:12:08
// Constant exampleclass Constant1{static final int NUMBER_OF_MONTHS = 12;static final double PI = (double) 22 / 7;public static void main( String args[] ){ System.out.println("NUMBER_OF_MONTHS : " + NUMBER_OF_MONTHS ); System.out.println("PI : " + PI );}}Output:NUMBER_OF_MONTHS : 12PI : 3

Dynamic Variable Initiazation in Java

Filed under: Java on 2023-08-11 19:11:40
// Program to show dynamic variable initialization of variableclass  DynInit{public static void main( String args[ ] ){ double a = 8.0, b = 6.0; // c is dynamically initialized double c = Math.sqrt(a * a + b * b); System.out.println("Hypotenuse is " + c);}}Output:Hypotenuse 

Boolean Data Type in Java

Filed under: Java on 2023-08-11 19:09:55
// Boolean variable Exampleclass BoolTest {public static void main(String args[ ]) { boolean b; b = false; System.out.println("b is " + b); b = true; System.out.println("b is " + b); if(b) {    System.out.println("This is executed."); }}}Ou

Character Demo in Java

Filed under: Java on 2023-08-11 19:09:03
// Character exampleclass  CharDemo {public static void main(String args[ ]) { char  aChar, bChar; aChar = 88;   // code for X bChar = 'Y'; System.out.print("aChar and bChar : "); System.out.println(aChar + " " + aChar); aChar++;    //

Java Program Comments

Filed under: Java on 2023-08-11 19:08:22
// Simple example of commentsclass Comments{// Your program begins with a call to main().// this is single line commentpublic static void main( String args[ ] ){ System.out.println("Java Programming Examples");/*   This is multiline comment  with multiple lines*/}}Output:Java Pro

Java Program for Calculating Interest

Filed under: Java on 2023-08-11 19:07:39
// Simple example to calculate Interestclass  CompInterest{public static void main( String args[ ] ){ double a, p, r ,n ,ci; p = 1000; r = 10; n = 3;      a = p * Math.pow(( 1 + ( r / 100.0 ) ), n );      ci = a - p;     System.ou

Java Program for Converting Rupees into Paisa

Filed under: Java on 2023-08-11 19:06:31
// Program to convert ruppes to paisapublic class SimpleConversion{   public static void main(String args[])   {                      double n=56.50;           int a=(int) n;    &n

Java Program for Area Of Triangle

Filed under: Java on 2023-08-11 19:05:40
// Program to find area of triangleclass   AreaTriangle{public static void main( String args[ ] ){ double area, a, b, c, s; a = 3; b = 4; c = 5; s = (a + b + c) / 2; area = Math.sqrt( s * (s-a) * (s-b) * (s-c) ); System.out.println("Area of Triangle is = " + a

Java Program for finding the area of Circle

Filed under: Java on 2023-08-11 19:05:05
// Program to find area of circleclass  AreaCircle{ public static void main( String args[ ] ){ double rad; final double PI = 3.14159; rad = 10.0; double area = PI * rad * rad; System.out.print( "\n Area of Circle is = " + area );}}Output:Area of Circle is = 314.159

Hello World Program in Java

Filed under: Java on 2023-08-11 19:02:38
// Hello World Exampleclass  FirstProgram    {         public static void main( String args[ ] )         {         System.out.println("Hello Java World..!" );         }    }Ou

Arrow Function in JavaScript

Filed under: JavaScript on 2023-08-07 19:00:15
In this post, we are going to show you arrow function. Watch the below example carefully.<!DOCTYPE html><html><body><h1>JavaScript Functions</h1><h2>The Arrow Function</h2><p>This example shows the syntax of an Arrow Function, and how to use it.&l

How to Iterate an array elements using For Loop in JavaScript

Filed under: JavaScript on 2023-08-06 23:04:29
In this post, you will see how you can iterate elements of an array in javascript.Note: here we have an array of numbers.We can find the number of elements in this array by using array.length i.e 6. Now we will run for loop six times to print all the elements.All of you know that array starts w

For Loop Iteration In JavaScript

Filed under: JavaScript on 2023-08-06 22:39:18
In this example, we will see for loop iteration. We have taken one blank array. We will push the values in this array using for loop. Below is the complete example of this action.<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <meta nam

While Loop example in JavaScript

Filed under: JavaScript on 2023-08-06 22:03:24
In this post we will see while loop in JavaScript. While loop keep working until the condition is true. As soon as the condition is false it stops.For example we have taken one array here and we will push the values in this array with the help of while loop.<!DOCTYPE html><html lang="en">

Return the Remainder from Two Numbers in JavaScript

Filed under: JavaScript on 2023-08-06 21:08:07
There is a single operator in JavaScript, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value. Examplesremainder(1, 3) ➞ 1remainder(3, 4) 

Write a code to find Maximum Edge of a Triangle in JavaScript

Filed under: JavaScript on 2023-08-06 21:00:59
Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. Examples:nextEdge(8, 10) ➞ 17nextEdge(5, 7) ➞ 11nextEdge(9, 2) ➞ 10 Notes:We will use this algorithm to find the maximum range of a triangle's third edge(side1 + side2)

Convert Hours into Seconds in JavaScript

Filed under: JavaScript on 2023-08-06 20:57:35
Write a function that converts hours into seconds. Examples:howManySeconds(2) ➞ 7200howManySeconds(10) ➞ 36000howManySeconds(24) ➞ 86400Notes:   60 seconds in a minute, 60 minutes in an hour <script>function howManySeconds(hour){var seconds = hour * 60 * 60 *;} v

Power Calculator in JavaScript

Filed under: JavaScript on 2023-08-06 20:54:31
Create a function that takes voltage and current and returns the calculated power.Examples:circuitPower(230, 10) ➞ 2300circuitPower(110, 3) ➞ 330circuitPower(480, 20) ➞ 9600Notes:Requires basic calculation of electrical circuits. Power = voltage * current; We will use this calculation in 

Return the First Element in an Array in JavaScript

Filed under: JavaScript on 2023-08-06 20:50:56
Create a function that takes an array containing only numbers and return the first element.Examples:getFirstValue([1, 2, 3]) ➞ 1

getFirstValue([80, 5, 100]) ➞ 80getFirstValue([-500, 0, 50]) ➞ -500Notes:The first element in an array always has an index of 0.Code: <script>function 

Convert Age to Days in JavaScript

Filed under: JavaScript on 2023-08-06 20:43:43
Create a function that takes the age in years and returns the age in days.Examples:calcAge(65) ➞ 23725

calcAge(0) ➞ 0

calcAge(20) ➞ 7300 Notes:Use 365 days as the length of a year for this challenge.Ignore leap years and days between last birthday and now.Expect only positive intege

Write a program in JavaScript to find the Area of Triangle

Filed under: JavaScript on 2023-08-06 20:41:33
Write a function that takes the base and height of a triangle and return its area.Examples:triArea(3, 2) ➞ 3

triArea(7, 4) ➞ 14

triArea(10, 10) ➞ 50 We will make a function triArea(base, height) which will take two values as parametersNotes:The area of a triangle is: (base * height)

Convert Minutes into Seconds in JavaScript

Filed under: JavaScript on 2023-08-06 20:35:41
Write a function that takes an integer minutes and converts it to seconds.Examples:convert(5) ➞ 300

convert(3) ➞ 180

convert(2) ➞ 120 Code<script>function convert(minutes){return minutes * 60;  //1 minutes equals to 60 seconds.}convert(5) // output 300convert(3) // output

Return the Sum of Two Numbers in JavaScript

Filed under: JavaScript on 2023-08-06 20:33:00
Create a function that takes two numbers as arguments and returns their sum.Examplesaddition(3, 2) ➞ 5

addition(-3, -6) ➞ -9

addition(7, 3) ➞ 10 Code: <script>function addition(a, b){return a+b;} addition(3, 2); //output 5addition(-3, -6); //output -9addition(7, 3); 

What are the types of errors in javascript?

Filed under: JavaScript Interview Questions on 2022-08-06 09:35:56
There are two types of errors in javascript.Syntax error: Syntax errors are mistakes or spelling problems in the code that cause the program to not execute at all or to stop running halfway through. Error messages are usually supplied as well.Logical error: Reasoning mistakes occur when the syntax i

What is DOM?

Filed under: JavaScript Interview Questions on 2022-08-06 09:35:08
DOM stands for Document Object Model.  DOM is a programming interface for HTML and XML documents.When the browser tries to render an HTML document, it creates an object based on the HTML document called DOM. Using this DOM, we can manipulate or change various elements inside the HTML document.

What do you mean by BOM in Javascript?

Filed under: JavaScript Interview Questions on 2022-08-06 09:33:31
Browser Object Model is known as BOM. It allows users to interact with the browser. A browser's initial object is a window. As a result, you may call all of the window's functions directly or by referencing the window. The document, history, screen, navigator, location, and other attributes are avai

What do mean by prototype design pattern?

Filed under: JavaScript Interview Questions on 2022-08-05 07:33:58
The Prototype Pattern produces different objects, but instead of returning uninitialized objects, it produces objects that have values replicated from a template – or sample – object. Also known as the Properties pattern, the Prototype pattern is used to create prototypes.The introduction of bus

Explain WeakSet in javascript

Filed under: JavaScript Interview Questions on 2022-08-02 06:13:53
In javascript, a Set is a collection of unique and ordered elements. Just like Set, WeakSet is also a collection of unique and ordered elements with some key differences:Weakset contains only objects and no other type.An object inside the weakset is referenced weakly. This means, that if the object 

Why do we use callbacks in Javascript?

Filed under: JavaScript Interview Questions on 2022-08-02 06:12:44
A callback function is a method that is sent as an input to another function (now let us name this other function "thisFunction"), and it is performed inside the thisFunction after the function has completed execution.JavaScript is a scripting language that is based on events. Instead of waiting for

Methods to include JavaScript in HTML Code?

Filed under: JavaScript on 2022-07-16 17:12:56
Javascript can be added to our HTML code in mostly 2 ways:Internal Javascript: Javascript in this case is directly added to the HTML code by adding the JS code inside the <script> tag, which can be placed either inside the <head> or the <body> tags based on the requirement of the u

What are the features of JavaScript?

Filed under: JavaScript on 2022-07-16 17:11:22
Following are the features of javascript:It was developed with the main intention of DOM manipulation, bringing forth the era of dynamic websites.Javascript functions are objects and can be passed in other functions as parameters.Can handle date and time manipulation.Can perform Form Validation.A co

What is NaN property in JavaScript?

Filed under: JavaScript Interview Questions on 2022-07-04 19:30:33
NaN property represents the “Not-a-Number” value. It indicates a value that is not a legal number.typeof of NaN will return a Number.To check if a value is NaN, we use the isNaN() function,Note- isNaN() function converts the given value to a Number type, and then equates to NaN.isNaN("Hello") &n

Explain Hoisting in javascript

Filed under: JavaScript Interview Questions on 2022-07-03 07:56:47
Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.This means that irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.Example 1:hoistedVariable = 3;

What do you understand by classes in java?

Filed under: JAVA Interview Questions on 2022-07-02 16:09:45
In Java, a class is a user-defined data type from which objects are created. It can also be called as a blueprint or prototype. A class is a collection of various methods and variables which represent a set of properties that are common to all the objects of one type. A class includes components suc

What do you mean by an object in java?

Filed under: JAVA Interview Questions on 2022-07-02 16:09:28
An object is a basic entity in an object-oriented programming language that represents the real-life entities. Many objects are created by a java program that interacts with the invoking methods. The state of an object is represented by its attributes and reflects its properties. The behavior of an 

Compare java and python.

Filed under: JAVA Interview Questions on 2022-07-02 16:09:13
Java and Python, both the languages hold an important place in today’s IT industry. But in some factors, one is better than the other. Such factors are:Java is easy to use, whereas Python is very good in this case.The speed of coding in Java is average, whereas in Python it is excellent.In Java, t

Outline the major features of Java.

Filed under: JAVA Interview Questions on 2022-07-02 16:08:52
The major features of Java are listed below: –Object-oriented: – Java language is based on object-oriented programming. In this, the class and the methods describe the state and behavior of an object. The programming is done by relating a problem with the real world object.Portable: – the conv

Looping in JAVA and Types of Loops in JAVA

Filed under: JAVA Interview Questions on 2022-07-02 16:08:18
If we want to execute a statement or a block of statements repeatedly in java, then loops are used. And such a process is known as looping. There are basically 3 types of looping. They are: –"For loop": – for executing a statement or a set of statements for a given number of times, for loops are

What are the various access specifiers in Java?

Filed under: JAVA Interview Questions on 2022-07-02 16:07:16
Access specifiers in java are the keywords which define the access scope of the function. It can be used before a class or a method. There are basically 4 types of access specifiers in java: –Public: – class, methods, and fields are accessible from anywhere.Protected: – methods and fields are 

What is the difference between JDK, JRE, and JVM?

Filed under: JAVA Interview Questions on 2022-07-02 16:06:54
It is important to understand the difference between JDK, JRE, and JVM in Java.JVM (Java Virtual Machine):  Java virtual machine is actually an abstract machine which provides a runtime environment in which the java bytecode gets executed. A JVM performs some main tasks such as- loading, verify

What is the need of the JAVA?

Filed under: JAVA Interview Questions on 2022-07-02 16:05:12
The need of Java is that it enforces an object-oriented programming model and can be used to create complete applications that can run on a single computer or be distributed across servers and clients in a network thus it can easily build mobile applications or run on desktop applications that use d

What are the different data types present in javascript?

Filed under: Javascript on 2022-07-02 07:56:54
To know the type of a JavaScript variable, we can use the typeof operator.Primitive types String - It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.Example :var str = "Vivek Singh Bisht"; //using double quotes
var str

What are disadvantage of JavaScript?

Filed under: JavaScript on 2022-06-29 18:09:25
Some of the disadvantages of JavaScript are:

a)    No support for multithreading
b)    No support for multiprocessing
c)    Reading and writing of files is not allowed
d)    No support for networking applications.

List some features of JavaScript

Filed under: JavaScript on 2022-06-29 18:07:32
Some of the features of JavaScript are:
1.    Lightweight
2.    Interpreted programming language
3.    Good for the applications which are network-centric
4.    Complementary to Java
5.    Complementary to HTML
6.    Open source
7.    Cross-platform 

What is JavaScript?

Filed under: JavaScript on 2022-06-29 18:06:48
JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the we